package com.tedu.egmvc.controller;

import com.tedu.egmvc.mapper.AddressMapper;
import com.tedu.egmvc.pojo.dto.AddressDTO;
import com.tedu.egmvc.pojo.entity.Address;
import io.swagger.annotations.*;
import org.apache.catalina.mbeans.UserMBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Controller
@Api(tags = "地址模块")
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @ApiOperation(value = "添加地址信息")
    @RequestMapping("/insert")
    @ResponseBody
    public String insert(AddressDTO addressDTO){
        Address address=new Address();
        BeanUtils.copyProperties(addressDTO,address);
        addressMapper.insert(address);
        return "添加成功";
    }
    @RequestMapping("/select")
    @ResponseBody
    @ApiOperation(value = "查询地址信息")
    public List<Address>addressSelect (){
        List<Address>addressList=addressMapper.addressSelect();
        return addressList;
    }

    @ApiOperation(value = "删除地址信息")
    @RequestMapping("/delete")
    @ResponseBody
    public String delete(int id){
        int num= addressMapper.delete(id);
        return num>0?"删除成功":"删除失败";
    }

    @ApiOperation(value = "修改地址信息")
    @RequestMapping("/update")
    @ResponseBody
    public String update(AddressDTO addressDTO){
        Address address=new Address();
        BeanUtils.copyProperties(addressDTO,address);
        addressMapper.update(address);
        return "修改成功";
    }
}
